//入口
module.exports = function (app) {

  const config = require('../config/config.js');
  const mydb = require('../database/index.js');



  mydb.connect(config.myconnect, { useMongoClient: true }); //建立连接
  const conmesage = mydb.connection;
  conmesage.on('error', () => {  // 数据库连接失败
    app.use((req, res) => {
      return res.json({ code: 203, mes: '数据库连接错误' });
    });
  });

  conmesage.once('open', function () {

    app.use('/user', require('./user'));

    // catch 404 and forward to error handler
    app.use(function (req, res, next) {
      var err = new Error('Not Found');
      err.status = 404;
      next(err);
    });
    // error handler
    app.use(function (err, req, res, next) {
      // set locals, only providing error in development
      res.locals.message = err.message;
      res.locals.error = req.app.get('env') === 'development' ? err : {};
      // render the error page
      res.status(err.status || 500);
      res.render('error');
    });
  });
};